﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.IO;

namespace EpsiRisk.MoteurJeu
{
    public static class ClassGestionSauvegardes
    {
        public static Thread t;
        public static Stream s;

        public static void sauvegarderPartie()
        {
            t = new Thread(new ThreadStart(sauver));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            
        }

        private static void sauver()
        {
            SaveFileDialog sf = new SaveFileDialog();
            sf.InitialDirectory = Settings.Default.SavePath;
            sf.Title = "Sauvegarde de la partie";
            sf.FileName = "sauvegarde";
            sf.AddExtension = true;
            sf.DefaultExt = "Risk";
            sf.FileOk += new System.ComponentModel.CancelEventHandler(sf_FileOk);
            sf.ShowDialog();
        }

        static void sf_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {

            s=((SaveFileDialog)sender).OpenFile();
            StreamWriter sw = new StreamWriter(s);
            sw.WriteLine("TEST");
            sw.Close();
            //TODO

        }

        public static void chargerPartie()
        {
            t = new Thread(new ThreadStart(charger));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private static void charger()
        {
            OpenFileDialog of = new OpenFileDialog();
            of.InitialDirectory = Settings.Default.SavePath;
            of.Title = "Chargement de la partie";
            of.FileName = "sauvegarde";
            of.AddExtension = true;
            of.DefaultExt = "Risk";
            of.FileOk += new System.ComponentModel.CancelEventHandler(of_FileOk);
            of.ShowDialog();
        }

        static void of_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            s = ((OpenFileDialog)sender).OpenFile();
            StreamReader sr = new StreamReader(s);
            sr.Close();
            //TODO

        }
    }
}
